package cn.foolishbird.crow.spring.security;

import cn.foolishbird.crow.enumeration.AbleEnum;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 默认的用户信息详情
 *
 * @author foolish bird
 * @email luohongtu@foolishbird.cn
 */
public class DefaultUserDetails<T> implements UserDetails {

    private static final long serialVersionUID = -2275397690945426951L;

    /**
     * 用户账号
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 帐号状态
     */
    private AbleEnum userStatus;

    /**
     * 权限
     */
    private List<GrantedAuthority> authorities;

    /**
     * 用户
     */
    private T userInfo;

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return AbleEnum.ABLE.equals(this.userStatus);
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public AbleEnum getUserStatus() {
        return userStatus;
    }

    public void setUserStatus(AbleEnum userStatus) {
        this.userStatus = userStatus;
    }

    public void setAuthorities(List<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public T getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(T userInfo) {
        this.userInfo = userInfo;
    }
}
